package com.bingxue.edu.management.shop.controller;

import com.bingxue.edu.framework.common.model.Response;
import com.bingxue.edu.framework.security.ApiResource;
import com.bingxue.edu.management.shop.model.entity.Activity;
import com.bingxue.edu.management.shop.service.ActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "营销活动接口")
@RestController
@RequestMapping("/shop/activity")
@RequiredArgsConstructor
public class ActivityController {

    private final ActivityService activityService;

    @Operation(summary = "查询营销活动列表")
    @ApiResource("shop:activity:read")
    @GetMapping("/list")
    public Response<List<Activity>> list() {
        return Response.success(activityService.list());
    }

    @Operation(summary = "修改营销活动配置")
    @ApiResource("shop:activity:write")
    @PostMapping("/update/{id}")
    public Response<Void> update(@PathVariable String id, @RequestBody Activity req) {
        Activity activity = activityService.copyById(req, id);
        activityService.updateById(activity);
        return Response.success();
    }
}
